<template>
  <div class="orderTableList">
    <!-- 列表查询 -->
    <UserSearch @search="reload"></UserSearch>
    <el-card class="box-card"
             shadow="never">
      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection"
                     :disabled="false"
                     cache-key="systemUserTable">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>

        </template>
        <!-- 名称 -->
        <template v-slot:realName="{ row }">
          <div class="realNameStyle flex">
            <img class="avaterName"
                 :src="row.avatar"
                 alt="" />
            <div class="flex-column-start">
              <div style="width: 40px">{{ row.nickname }}</div>
            </div>
          </div>
        </template>

        <template v-slot:refundFare="{ row }">
          <div>
            <div>{{ row.refundFare?row.refundFare:0 }}</div>

          </div>
        </template>
        <template v-slot:refundHandlingCharge="{ row }">
          <div>
            <div>{{ row.refundHandlingCharge?row.refundHandlingCharge:0 }}</div>

          </div>
        </template>
        <!-- 收款账号 -->

        <!-- 体现类型 -->
        <template v-slot:withdrawAccount="{ row }">
          <div>{{ row.withdrawAccount ? row.withdrawAccount : '-- --' }}</div>
        </template>

        <!-- 操作 -->
        <template v-slot:action="{ row }">
          <el-popconfirm class="ele-action"
                         title="是否要进行退款操作"
                         v-if="!(row.refundProcess==3)"
                         @confirm="requestRefund(row)">
            <template v-slot:reference>
              <el-link type="primary"
                       :underline="false"
                       icon="el-icon-document"
                       v-show="!row.refuseReason">
                申请退款
              </el-link>
            </template>
          </el-popconfirm>

          <el-link type="danger"
                   :underline="false"
                   v-if="!(row.refundProcess==3)"
                   icon="el-icon-document-delete"
                   @click="viewDetail(row)">
            {{ !row.refuseReason?'申请驳回':'驳回原因' }}
          </el-link>

          <el-popconfirm class="ele-action"
                         title="是否确定要删除该信息"
                         @confirm="remove(row)">
            <template v-slot:reference>
              <el-link type="danger"
                       icon="el-icon-delete"
                       :underline="false">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
      <!-- 技师状态 -->
      <technicianStatusEdit :visible.sync="visible"
                            @reloadRefuseReason="reload"
                            :data="currentId"> </technicianStatusEdit>
    </el-card>

  </div>
</template>
<script>
import {

  sitePlatformConfigDetail,
  refundIst

} from '@/api/basicConfiguration/platformConfiguration';
import UserSearch from './user-search.vue';
import technicianStatusEdit from './technicianStatusEdit.vue';
import drawerReflect from '../components/drawerReflect.vue';
import { reflectTableList } from '../constant/constant';
import { refundIstList, refundIstUpdate, refundIstListDelete } from '@/api/orderManagement/refundRequestList/index'
export default {
  name: 'reflectList',
  components: {

    UserSearch,
    technicianStatusEdit
  },
  data () {
    return {
      reflectTableList,
      //  技能评分
      colors: ['#99A9BF', '#F7BA2A', '#FF9900'],
      value: 4,
      visible: false,
      timeoutId: null,
      // 表格列配置
      columns: [
        {
          prop: 'orderNumber',
          label: '下单编号',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'orderNumber'
        },

        {
          prop: 'refundFare',
          label: '扣款车费',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'refundFare'
        },
        {
          prop: 'refundAmount',
          label: '退款金额',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'refundAmount'
        },

        {
          prop: 'disbursements',
          label: '实付款',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'disbursements'
        },

        {
          prop: 'refundHandlingCharge',
          label: '退款手续费',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 150,
          slot: 'refundHandlingCharge'
        },
        {
          prop: 'refundInstructions',
          label: '退款说明',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 150,
          slot: 'refundInstructions'
        },

        // {
        //   prop: 'refundVoucher',
        //   label: '退款凭证',
        //   sortable: 'custom',
        //   align: 'center',
        //   showOverflowTooltip: true,
        //   minWidth: 110,
        //   slot: 'refundVoucher'
        // },
        {
          prop: 'createdAt',
          label: '申请时间',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'createdAt',
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 320,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true,

          fixed: 'right'
        }
      ],
      currentId: null,
      // 表格选中数据
      selection: [],
      drawerReflectBoolen: false
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    },

    // 实名认证

  },
  activated () {
    this.reload()
  },
  methods: {

    requestRefund (row) {

      clearTimeout(this.timeoutId);
      this.timeoutId = setTimeout(() => {
        this.visibleModalFn(row);
      }, 200);
    },
    async visibleModalFn (row) {
      console.log('1111')

      const res = await refundIst({
        siteId: this.$store.state.site.info.id, // 站点id
        userId: row.userId, //登录用户的id
        // 订单id
        orderId: row.orderId,
        // 订单编号
        orderNumber: row.orderNumber,
        // 退款金额 = 实付款 + 已经扣除的手续费
        refundAmount: Number(row.refundAmount),
        // 实付款 
        disbursements: Number(row.disbursements),
        // 退款流程 (1.提交申请 2.审核通过 3.退款成功 )
        refundProcess: 1, // 默认传1
        // 退款数量
        number: row.number,
        // 退款原因
        refund: '其他',
        // 退款说明
        refundInstructions: row.refundInstructions,
        // 退款凭证
        refundVoucher: '', //图片，最多九张用英文逗号隔开
        // 服务/订单状态  1.待接单 2.已接单（待服务） 3.服务中 4.已完成 5.已取消/退款
        status: 5
      })

      //   const res = await refundIst({
      //     siteId: 6, // 站点id
      //     userId: 379, //登录用户的id
      //     // 订单id
      //     orderId: 8,
      //     // 订单编号
      //     orderNumber: '202401181156280003',
      //     // 退款金额 = 实付款 + 已经扣除的手续费
      //     refundAmount: ,
      //     // 实付款 
      //     disbursements: 0.01,
      //     // 退款流程 (1.提交申请 2.审核通过 3.退款成功 )
      //     refundProcess: 1, // 默认传1
      //     // 退款数量
      //     number: 1,
      //     // 退款原因
      //     refund: '其他',
      //     // 退款说明
      //     refundInstructions: '5859',
      //     // 退款凭证
      //     refundVoucher: '', //图片，最多九张用英文逗号隔开
      //     // 服务/订单状态  1.待接单 2.已接单（待服务） 3.服务中 4.已完成 5.已取消/退款
      //     status: 5
      //   })
      console.log(res)
      if (res.code == 200) {
        this.$message.success('退款成功')
        this.reload();

      } else {
        this.reload();
        this.$message.success('退款失败')
      }
    },

    // 点击查看详情弹出详情抽屉
    viewDetail (row) {
      console.log(row);

      if (!row.refuseReason) {
        this.currentId = row;
        // 用户余额管理
        this.visible = !this.visible;
      } else {
        // 直接发回驳回原因
        this.currentId = row;
        // 用户余额管理
        this.visible = !this.visible;
      }
    },

    /* 表格数据源 */
    datasource ({ page, limit, where, order }) {
      return refundIstList({
        page,
        limit,
        ...where,

        siteId: this.$store.state.site.info.id
      });
    },
    /* 刷新表格 */
    reload (where) {
      this.$refs.table.reload({ page: 1, where: where, types: 1 });
    },

    /* 删除 */
    remove (row) {
      const loading = this.$loading({ lock: true });
      refundIstListDelete(row.id)
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
    },
    /* 批量删除 */
    removeBatch () {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      console.log(this.selection);
      this.$confirm('确定要删除选中的信息吗?', '提示', {
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({ lock: true });
          console.log(this.selection.map((d) => d.id));
          technicianWithdrawalBatch(this.selection.map((d) => d.id))
            .then((msg) => {
              loading.close();
              this.$message.success(msg);
              this.reload();
            })
            .catch((e) => {
              loading.close();
              this.$message.error(e.message);
            });
        })
        .catch(() => { });
    }
  }
};
</script>
<style lang="less" scoped>
/deep/ .el-textarea__inner {
  height: 100px;
}
.orderTableList {
  .realNameStyle {
    .avaterName {
      width: 41px;
      height: 41px;
      border-radius: 36px;
      vertical-align: middle;
      margin-right: 5px;
    }
    .technicianName {
      color: #1890ff;
      font-size: 12px;
      font-style: normal;
      font-weight: 400;
    }
  }
  .orderrowinfo {
    width: 100%;
    display: flex;
    margin-left: 15px;
    padding: 30px;
    height: 50px;
    align-items: center;
    background-color: #f8f8f8;
    .orderNumber,
    .createDate,
    .buyName,
    .iphone {
      margin-right: 40px;
      color: #000;
      font-family: Inter;
      font-size: 14px;
      font-style: normal;
      font-weight: 400;
    }
  }
}
</style>
